<script type="text/javascript" src="/static/lib/clipboard/clipboard-2.0.4.min.js"></script>

{% if file != None and _user_name == file.creator and op == "view" %}

{% if file.type == "gallery" %}
    <a class="btn" href="/note/management?parent_id={{file.id}}">管理</a>
{% elif file.type == "csv" %}
    <!-- nothing here -->
{% else %}
    <a class="btn" href="/note/edit?id={{file.id}}&is_iframe={{is_iframe}}">编辑</a>
{% end %}

<div class="dropdown">
    <span class="dropdown-btn link btn">更多▾</span>
    <div class="dropdown-content">
        <a class="dropdown-option link" href="javascript:rename('{{item.id}}', '{{item.name}}')">重命名</a>
        {% if file.is_public %}
            <a class="dropdown-option link" href="/note/share/cancel?id={{file.id}}">取消公开分享</a>
        {% else %}
            <a class="dropdown-option link" href="/note/share?id={{file.id}}">公开分享</a>
        {% end %}

        <a class="dropdown-option link link-share-option" href="javascript:void(0)" data-clipboard-text="">链接分享</a>
        <a class="dropdown-option link copy-link-option" href="javascript:void(0)" data-clipboard-text="">复制链接</a>
        
        <a class="dropdown-option move-btn link" data-url="/note/group/select?callback=moveNoteCallback">移动</a>

        {% if file.priority > 0 %}
            <a class="dropdown-option link" href="/note/unstick?id={{file.id}}">取消置顶</a>
        {% else %}
            <a class="dropdown-option link" href="/note/stick?id={{file.id}}">置顶</a>
        {% end %}

        {% if file.archived %}
            <a class="dropdown-option link" href="/note/unarchive?id={{file.id}}">取消归档</a>
        {% end %}

        {% if _is_admin and file.type == "gallery" %}
            <a class="dropdown-option link" href="/fs/{{file.path}}">管理文件</a>
        {% end %}

        <a class="dropdown-option link" href="/note/history?id={{file_id}}">{{T("历史")}}</a>
        <a class="dropdown-option link" href="/note/print?id={{file.id}}" target="_blank">打印</a>

        {% if _is_admin %}
            <a class="dropdown-option link" href="/note/{{file.id}}?_format=json">查看JSON</a>
        {% end %}

        <a class="dropdown-option-red" href="javascript:remove('{{item.id}}', '{{item.name}}', '{{item.parent_id}}')">删除</a>
    </div>
</div>
{% end %}
<!-- <a href="javascript:history.back()">返回</a> -->

<div class="share-tpl hide">
    <p>分享链接: <span class="share-link-text"></span></p>
    <div class="row">
        <button class="share-link-btn btn float-right" data-clipboard-text="">复制</button>
    </div>
</div>

<script type="text/javascript">
$(function () {
    $(".link-share-option").click(function(event) {
        /* Act on the event */
        $.post("/note/link_share", {id: "{{file.id}}"}, function (resp) {
            if (resp.code == "success") {
                var link = window.location.protocol + "//" + window.location.host + resp.data;
                $(".share-link-text").text(link);
                $(".share-link-btn").attr("data-clipboard-text", link);
                var html = $(".share-tpl").html();
                layer.confirm(html, {
                    btn: [] //按钮
                });
                new ClipboardJS('.share-link-btn', {
                    text: function(trigger) {
                        xnote.toast("已经复制到粘贴板");
                        return trigger.getAttribute('data-clipboard-text');
                    }
                });
            } else {
                xnote.alert("分享失败!");
            }
        });
    });

    $(".copy-link-option").click(function(event) {
        $(".copy-link-option").attr('data-clipboard-text', window.location.href);
        new ClipboardJS(".copy-link-option", {
            text: function (trigger) {
                xnote.toast("已经复制到粘贴板");
                return trigger.getAttribute("data-clipboard-text");
            }
        });
    });

    window.moveNoteCallback = function (parentId) {
        var selfId = "{{file.id}}";
        $.post("/note/move", {id:selfId, parent_id: parentId}, function (resp){
              console.log(resp);
              window.location.reload();
        });
    }
})
</script>